package com.wx.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.wx.dao.WxTemplatePushMapper;
import com.wx.entity.WxTemplatePush;
import com.wx.entity.WxTemplatePushExample;
import com.wx.service.WxTemplatePushService;

@Service("WxTemplatePushService")
public class WxTemplatePushImpl implements WxTemplatePushService {

	private WxTemplatePushMapper wxTemplatePushMapper;
	
	@Override
	public int add(WxTemplatePush model){
		return this.wxTemplatePushMapper.insert(model);
	}

	@Override
	public List<WxTemplatePush> findByExample(WxTemplatePushExample example){
		return this.wxTemplatePushMapper.selectByExample(example);
	}

	@Override
	public int deleteByExample(WxTemplatePushExample example){

		return this.wxTemplatePushMapper.deleteByExample(example);
	}

	@Override
	public int updateByRecord(WxTemplatePush record){
		return this.wxTemplatePushMapper.updateByPrimaryKeySelective(record);
	}
	
	@Resource
	public void setWxTemplatePushMapper(WxTemplatePushMapper WxTemplatePushMapper){
	
		this.wxTemplatePushMapper = WxTemplatePushMapper;
	}

	@Override
	public WxTemplatePush findByTemplateNoAndWxid(String templateNo, String wxid) {
		WxTemplatePushExample example = new WxTemplatePushExample();
		example.createCriteria().andTemplatenoEqualTo(templateNo).andWxidEqualTo(wxid);
		List<WxTemplatePush> list = wxTemplatePushMapper.selectByExample(example);
		if (list != null && list.size() == 1) {
			return list.get(0);
		}else{
			return null;
		}
	}

	@Override
	public WxTemplatePush findByPrimaryKey(Integer id) {
		return wxTemplatePushMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(WxTemplatePush record) {
		return wxTemplatePushMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public WxTemplatePush findByTemplateNo(String templateNo) {
		WxTemplatePushExample example = new WxTemplatePushExample();
		example.createCriteria().andTemplatenoEqualTo(templateNo);
		PageHelper.startPage(1,1);
		List<WxTemplatePush> list = wxTemplatePushMapper.selectByExample(example);
		if (list != null && list.size() == 1) {
			return list.get(0);
		}else{
			return null;
		}
	}
}
